<?php 
//thutrang
class ControllerMartCrmRegisterCustomer extends Controller {  
  	public function index() {
		

                $this->load->language('Mart_Crm/CRM_Report');
                if (isset($this->request->get['print'])) {
                    
			 $this->data['print'] = $this->request->get['print'];
		} else {
			 $this->data['print'] = "false";
		}
                
                if (isset($this->request->get['filter_group'])) {
			$filter_group = $this->request->get['filter_group'];
		} else {
			$filter_group = '2009';
		}
                
                $url = '';
		$this->data['groups'] = array();
                $this->data['groups'][] = array(
			'text'  => $this->language->get('text_2009'),
			'value' => '2009',
		);
                $this->data['groups'][] = array(
			'text'  => $this->language->get('text_2010'),
			'value' => '2010',
		);
                $this->data['groups'][] = array(
			'text'  => $this->language->get('text_2011'),
			'value' => '2011',
		);

		$this->data['groups'][] = array(
			'text'  => $this->language->get('text_2012'),
			'value' => '2012',
		);

                $this->data['groups'][] = array(
			'text'  => $this->language->get('text_2013'),
			'value' => '2013',
		);

		$this->data['groups'][] = array(
			'text'  => $this->language->get('text_2014'),
			'value' => '2014',
		);

		$this->data['groups'][] = array(
			'text'  => $this->language->get('text_2015'),
			'value' => '2015',
		);				
		
		if (isset($this->request->get['filter_group'])) {
			$url .= '&filter_group=' . $this->request->get['filter_group'];
		}
                $this->data['rows'] = array();
		
		$data = array(
			'filter_group'           => $filter_group
		);
                
                $this->load->model('Mart_Crm/RegisterCustomer');
                
                $print =  $this->data['print'];
                
		$results = $this->model_Mart_Crm_RegisterCustomer->getRegisterCustomer($data);
              //$results = $this->model_Mart_Crm_Crm_customer->getcustomer($data);
                //print_r($results);
//               $this->data['rows'][] = array(
//                            
//                            'id'=> null,
//                            'name'=> null,
//                            'amount'=> null
//                       
//                        );
               
                            
        //print_r($results) ;
                
                $this->data['SoLuong'] = $this->language->get('SoLuong');
                $this->data['token'] = $this->session->data['token'];
                $this->data['text_no_results'] = $this->language->get('text_no_results');
                $this->data['heading_title'] = $this->language->get('heading_title');
		
		$this->data['column_date_start'] = $this->language->get('column_date_start');
		$this->data['column_date_end'] = $this->language->get('column_date_end');
		
		$this->data['entry_date_start'] = $this->language->get('entry_date_start');
		$this->data['entry_date_end'] = $this->language->get('entry_date_end');
		$this->data['entry_group'] = $this->language->get('entry_group');	
                $this->data['month'] = $this->language->get('month');

		$this->data['button_export_pdf'] = $this->language->get('button_export_pdf');
                $this->data['button_export_excel'] = $this->language->get('button_export_excel');
                $this->data['button_display'] = $this->language->get('button_display');
                
                $this->data['STT'] = $this->language->get('STT');
                $this->data['goods_name'] = $this->language->get('goods_name');
                $this->data['group_name'] = $this->language->get('group_name');
                $this->data['Doanhthu'] = $this->language->get('Doanhthu');
                
                $this->data['entry_group'] = $this->language->get('entry_group');
                   
                //print_r($results);

                foreach ($results as $result) {
			$this->data['rows'][] = array(
                            
                            'id'=> $result['id'],
                            'name'=> $result['name'],
                            'count'=> $result['count'],
                            'filter_group' => $filter_group
                        );
			
			}
                    
                // = true;
                        if($print == "false")
                        {
                $this->template = 'Mart_Crm/Register_Customer.tpl';
                 $this->data['export_excel'] = $this->url->link('tool/export/downloadregistercustomer', 'token=' . $this->session->data['token'] .'&filter_group='.$filter_group);
                $this->data['print'] = $this->url->link('Mart_Crm/Register_Customer', 'token=' . $this->session->data['token'] .'&filter_group='.$filter_group.'&print=true');
                        }
                        if($print == "true")
                        {
                $this->template = "Mart_Crm/Register_Customerprint.tpl";
                
                        }
		$this->children = array(
			'common/header',	
			'common/footer'	
		);
                
		
		$this->response->setOutput($this->render());
		
		
  	}
}
?>